package com.hncu.edu.info.manager.service;

import com.hncu.edu.info.manager.dao.OtherTeacherDao;
import com.hncu.edu.info.manager.dao.TeacherDao;
import com.hncu.edu.info.manager.domain.Teacher;

public class TeacherService {
    OtherTeacherDao teacherDao = new OtherTeacherDao();

    //判断老师是否存在,根据工号查找老师
    public boolean isExist(String addId) {
        //先假设找不到老师
        boolean flag = false;
        //创建对象接收数组
        Teacher[] arr = teacherDao.findAllTeacher();
        //遍历数组,找相同的学号
        for (int i = 0; i < arr.length; i++) {
            Teacher teacher = arr[i];
            if (teacher != null && teacher.getid().equals(addId)) {
                flag = true;
                break;
            }
        }
        //找到了，返回值为true
        if (flag) {
            return flag;
        }
        //找不到，返回值为false
        else {
            return flag;
        }
    }

    //添加老师
    public boolean addTeacher(Teacher teacher) {
        //接受布尔值，并且返回
        boolean flag = teacherDao.addTeacher(teacher);
        if (flag) {
            return flag;
        } else {
            return flag;
        }
    }

    //查找老师
    public Teacher[] findAllTeacher() {
        Teacher[] arr = teacherDao.findAllTeacher();
        //假设数组为空
        boolean flag = false;
        //遍历数组，看数组是否为空
        for (int i = 0; i < arr.length; i++) {
            Teacher teacher = arr[i];
            if (teacher != null) {
                flag = true;
                break;
            }
        }
        //假如数组不为空，flag为true
        if (flag) {
            return arr;
        } else {
            return null;
        }
    }

    //删除老师
    public void deleteTeacher(String deleteId) {
        teacherDao.deleteTeacher(deleteId);
    }
    // 修改老师
    public void upadateTeacher(Teacher teacher) {
        teacherDao.updateTeacher(teacher);
    }
}
